(function () {
    var module = {};
    var tools = Tools();
    var balance;
    var mobileCode = 0;
    module.init = function () {
        tools.getUserInfo();
        // 界面展示   tab   及  按钮  点击跳转
        $(document).on("click", ".toRecharge", function () {
            $('#rechargeTable').show();
            $('#withdrawalsTable').hide();
        });
        $(document).on("click", ".toWithdrawals", function () {
            $('#rechargeTable').hide();
            $('#withdrawalsTable').show();
        });
   
        $(document).on("click", ".bank_from_close", function () {
            $('#rechargeTable').show();
            $('#bank_list').hide();
        });
        $(document).on("click", "#recharge_kj", function () {
            $('.recharge_kj').show();
            $('.recharge_wy').hide();
            $('#recharge_kj').addClass('cur');
            $('#recharge_kj').removeClass('tabChange1');
            $('#recharge_wy').removeClass('cur');
            $('.recharge_other').addClass('tabChange');
            $('.recharge_other').removeClass('tabChange2');
        });
        $(document).on("click", "#recharge_wy", function () {
            $('.recharge_kj').hide();
            $('.recharge_wy').show();
            $('#recharge_kj').removeClass('cur');
            $('.recharge_other').addClass('tabChange2');
            $('#recharge_kj').addClass('tabChange1');
            $('#recharge_wy').addClass('cur');
            $('.recharge_other').addClass('tabChange')
        });
        check();
        //查询银行卡
        tools.doGet(accountURL +tools.apiURL.bankCard, {}, module.bankCard);
        //查询提现额度
        tools.doGet(accountURL +tools.apiURL.queryAccountInfo, {}, module.queryAccountInfo);
    };
    module.bankCard = function (data) {
        if (data.status == 0) {
            if(data.data!=null){
                var content = data.data;
                $('.backNum').append('<span class="bankName">'+content.name+'</span><span class="bankNum1">('+content.cardNo.substr(content.cardNo.length-4)+')</span>');
                $('.afterDown').after(' <img src="'+content.icon+'" class="backIcon">');
             
                //直接跳转提现
                if (window.location.href.indexOf('withdrawals') > 0) {
                    $('#rechargeTable').hide();
                    $('#withdrawalsTable').show();
                }
            }
        }
    };

    function ismoney(value) {
        var mny = /^\d+(\.\d+)?$/;
        return mny.test(value)
    }

    function check() {
        //银行卡
        $(document).on('keyup', '#User_card', function () {
            toCheckBank();
        });

        //快捷充值
        $(document).on('click','.subCz',function () {
            var money = $('#kj_money').val();
            var tag=true;
            if(money==''||money==null||money==undefined){
                tag=false;
                $("#message").text('请输入您的提现金额');
            }else if(!ismoney($('#kj_money').val())){
                $("#message").text('金额输入有误！');
                tag=false;
            }
            if(tag){
                var data ={money:$('#kj_money').val(),rechargeWay: "SWIFT"};
                //快捷充值
                tools.doPost(accountURL + tools.apiURL.buildRechargeParms,data, module.buildRechargeParms);
            }else{
                $("#alertMessage").fadeIn();
                setTimeout(function(){
                    $("#alertMessage").fadeOut();
                },2000);
            }
        });

        //网银充值
        $(document).on('click','.subWy',function () {
            var tag=true;
            var money = $('#wy_money').val();
            var tags=true;
            if(money==''||money==null||money==undefined){
                tags=false;
                $("#message").text('请输入您的提现金额');
            }else if(!ismoney($('#wy_money').val())){
                $("#message").text('金额输入有误！');
                tags=false;
            }
            if(tags==true){
                var data ={money:$('#wy_money').val(),rechargeWay: "WEB"};
                //网银充值
                tools.doPost(accountURL + tools.apiURL.buildRechargeParms,data, module.buildRechargeParms1);

            }else{
                $("#alertMessage").fadeIn();
                setTimeout(function(){
                    $("#alertMessage").fadeOut();
                },2000);
            }
        });

        //提现
        $(document).on('click','.subTx',function () {
            var tag=true;
            if($('#withMoney').val()>balance){
                $("#message").text('提现金额不能大于用户余额');
                tag=false;
            }else if($('#withMoney').val()==''||$('#withMoney').val()==null||$('#withMoney').val()==undefined){
                tag=false;
                $("#message").text('请输入您的提现金额');
            }else if(!ismoney($('#withMoney').val())) {
                $("#message").text('金额输入有误！');
                tag = false;
            }
            if(tag){
                formBank1();
            }else{
                $("#alertMessage").fadeIn();
                setTimeout(function(){
                    $("#alertMessage").fadeOut();
                },2000);
            }
        });

    }
    //校验银行卡
    function toCheckBank() {
        var tag = true;
        if ($.trim($('#User_card').val()).length == 0) {
            tag = false;
            mobileCode = 0;
        } else {
            if (tools.luhmCheck($.trim($('#User_card').val())) == false) {
                tag = false;
                mobileCode = 0;
            }
        }
        if (tag) {
            $('.correctCard').removeClass('onError');
            $('.correctCard').addClass('onRight');
        } else {
            $('.correctCard').removeClass('onRight');
            $('.correctCard').addClass('onError');
        }
        return tag;
    }


    //查询平台支持的所有银行
    module.supportBankList = function (data) {
        if (data.status == 0) {
            var content = data.data;
            if (content.length > 0) {
                var pro = '';
                for (var i = 0; i < content.length; i++) {
                    pro += '<tr><td>' + content[i].bankName + '</td> <td>借记卡</td> <td>' + content[i].singleUpperLimit + '</td> <td>' + content[i].dayUpperLimit + '</td> </tr>';
                }
                $('#bank_explain').append(pro);
            }
        }
    };

    /*--------------------------------充值------------------------------------------*/
    //快捷支付
    module.buildRechargeParms=function (data) {
        if(data.status==0){
            tools.formPost(data.data.actionUrl, data.data.parms);
        }else{
            $("#alertMessage").fadeIn();
            $("#message").text(data.message);
            setTimeout(function(){
                $("#alertMessage").fadeOut();
            },2000)
        }
        
    };

    //网银
    module.buildRechargeParms1=function (data) {
        if(data.status==0){
            tools.formPost(data.data.actionUrl, data.data.parms);
        }else{
            $("#alertMessage").fadeIn();
            $("#message").text(data.message);
            setTimeout(function(){
                $("#alertMessage").fadeOut();
            },2000)
        }
    };
    /*--------------------------------充值------------------------------------------*/


    /*--------------------------------提现-----------------------------------------*/
    //查询可提现额度
    module.queryAccountInfo=function (data) {
       if(data.status==0){
           balance=data.data.balance;
           $('#balance').text(balance+'元')
       }
           };
    var status_s = true;
    function formBank1(){
        var money=$('#withMoney').val();
        if(status_s==true){
            status_s = false;
            $('.inputBut').css({'background':'#aaa'});
            doPost(accountURL +tools.apiURL.buildWithdrawParms, {money:money}, module.getWithdrawParms);
        }
    }

    module.getWithdrawParms=function (data) {
        if (data.status == 0) {
            tools.formPost(data.data.actionUrl, data.data.parms);
        } else {
            $('.inputBut').css({'background': '#f31437'});
            $("#alertMessage").fadeIn();
            $("#message").text(data.message);
            setTimeout(function () {
                $("#alertMessage").fadeOut();
            }, 2000)
        }

    };
    /*--------------------------------提现------------------------------------------*/


    module.init();
})();